<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Ads extends Model
{
    //
    protected $table="ads";

    protected $primaryKey = 'id';

    protected $fillable = ['id','position_id','title','type','content','advurl','is_active',
                            'is_closed','sort'];

    protected $dates = ['deleted_at'];

    static $app_arr = ['index' => '首页', 'employ' => '就业指南',
                    'teaches' => '充电加油', 'bbs' => '社区',
                    'enterprise' => '企业招聘'];

    /**
     *
     *获取广告位的名称
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function getPositionName()
    {
        return $this->belongsTo('App\Models\AdsPosition', 'position_id');
    }

    public function attachment($id)
    {
        return DB::table('attachment')->where(['app'=>'ads','app_id'=>$id])->orderBy('created_at','desc')->first();
    }
}
